package cn.com.web.Servlet;

import cn.com.domain.Student;
import cn.com.service.StudentService;
import cn.com.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/DeleteStudentServlet")
public class DeleteStudentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取参数
        String sidstr = request.getParameter("sid");
        String stuname = request.getParameter("stuname");
        String sex = request.getParameter("sex");
        String academy = request.getParameter("academy");
        int sid=Integer.parseInt(sidstr);
        //创建service对象
        StudentService studentService=new StudentServiceImpl();
        //建立要删除的学生
        Student student=new Student(sid,stuname,sex,academy);
        studentService.deleteStudent(student);

        response.getWriter().write("删除成功");
        String path = request.getContextPath();
        response.getWriter().write("<a href='"
                +path+
                "/StudentListServlet  '>学生信息页面</a>\n");

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
